//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
// 			VisualNovelToolkit		     /_/_/_/_/_/_/_/_/_/.
// Copyright ©2013 - Sol-tribe.	/_/_/_/_/_/_/_/_/_/.
//_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/.
using UnityEngine;
using System.Collections;

public class ISpriteFactory : MonoBehaviour  {
	
	virtual public void OnSetActiveColor( GameObject obj ){}

	virtual public void OnSetDeactiveColor( GameObject obj ){}

	virtual public GameObject Create( ref SceneData.SceneNodeData data , GameObject node , Vector3 pos , Vector3 scl , GameObject parent ){
		return node;
	}
		
	virtual public void SaveData( ref SceneData.SceneNodeData dat ,  GameObject obj  ){
		if( obj == null ){
			ViNoDebugger.LogWarning( "obj NULL." );
		}
		dat.name= obj.name;
		if( obj.transform.parent != null ){
			dat.parentname = obj.transform.parent.name;
		}						
	     dat.posX=obj.transform.localPosition.x; 
	     dat.posY=obj.transform.localPosition.y; 
	     dat.posZ=obj.transform.localPosition.z; 			
	     dat.rotX=obj.transform.rotation.eulerAngles.x;
	     dat.rotY=obj.transform.rotation.eulerAngles.y;
	     dat.rotZ=obj.transform.rotation.eulerAngles.z;
	     dat.sclX=obj.transform.localScale.x;
	     dat.sclY=obj.transform.localScale.y;
	     dat.sclZ=obj.transform.localScale.z;		
	}
	
	virtual public void LoadData( ref SceneData.SceneNodeData dat ,  GameObject obj ){
        Vector3 VPosition = new Vector3(dat.posX,dat.posY,dat.posZ);              
        Vector3 VRotation = new Vector3(dat.rotX,dat.rotY,dat.rotZ);              
        Vector3 VScale = new Vector3(dat.sclX,dat.sclY,dat.sclZ);              
		
		obj.name = dat.name;	
		GameObject parent =  GameObject.Find ( dat.parentname );
		if( parent != null ){
			obj.transform.parent = parent.transform;
		}
        obj.transform.localPosition	= VPosition; 
        obj.transform.localRotation	= Quaternion.Euler( VRotation );
        obj.transform.localScale	= VScale; 		
	}

	virtual public void PreFadeoutAndDestroy( GameObject root ){}

	virtual public void OnFadeoutAndDestroy( GameObject root ){}

	protected GameObject CreateNode( string name , Transform parent ,  Vector3 pos , Vector3 scl ){		
		GameObject node = new GameObject();		// TODO : DO NOT NEW !			
		node.name = name;
		node.transform.parent = parent;
		node.transform.localPosition = pos;				
		node.transform.localScale = scl;
		return node;
	}
	
	
}